//随机乱序用户
var Random_users = function (users) {
  var _array = users;
  let i = users.length;
  while (i) {
    let j = Math.floor(Math.random() * i--);
    [users[j], users[i]] = [users[i], users[j]];
  }
  return _array;
};

//随机抽取n名获奖
var Random_lottery = function (users, ranNum) {
  var result = [];
  for (; result.length < ranNum;) {
    var ran = Math.floor(Math.random() * users.length);
    if (findInUsers(result, users[ran])) {
      result.push(users[ran]);
    }
  }
  return result;
}
// 判断用户有没有重复
var findInUsers = function (arr, obj) {
  const len = arr.length;
  for (let i = 0; i < len; i++) {
    // eslint-disable-next-line no-console
    if (arr[i]['id'] === obj.id) {
      return false
    }
  }
  return true
}

export {
  Random_users,
  Random_lottery,
}
